#ifndef __SPI_SD_H
#define __SPI_SD_H
 
#include "sys.h"


uint8_t SD_Init(void);
uint8_t SD_SendCommand(uint8_t cmd,uint32_t arg,uint8_t crc);
uint8_t SD_SendCommand_NoDeassert(uint8_t cmd,uint32_t arg,uint8_t crc);
uint8_t SD_ReceiveData(uint8_t *data,uint16_t len,uint8_t release);
uint8_t SD_GetCID(uint8_t *cid_data);
uint8_t SD_GetCSD(uint8_t *csd_data);
uint32_t SD_GetCapacity(void);
uint8_t SD_ReadSingleBlock(uint32_t sector, uint8_t *buffer);
uint8_t SD_ReadMultiBlock(uint8_t *buff, uint32_t sector, uint32_t count);
uint8_t SD_WaitReady(void);
uint8_t SD_WriteSingleBlock(uint32_t sector, const uint8_t *data);
uint8_t SD_WriteMultiBlock(const uint8_t *data, uint32_t sector, uint8_t count);

#define SD_CS   SPI3->U8SPIPORT.SS 


#define RELEASE 0
#define NO_RELEASE 1

#define SD_TYPE_V2     0
#define SD_TYPE_V2HC   1

#define CMD0                     0                       /* Reset */
#define CMD1                     1                         /* Send Operator Condition - SEND_OP_COND */
#define CMD8                     8                     /* Send Interface Condition - SEND_IF_COND	*/
#define CMD9                     9                       /* Read CSD */
#define CMD10                    10                  /* Read CID */
#define CMD12                    12                   /* Stop data transmit */
#define CMD16                    16                  /* Set block size, should return 0x00 */
#define CMD17                    17                  /* Read single block */
#define CMD18                    18                 /* Read multi block */
#define ACMD23                   23           /* Prepare erase N-blokcs before multi block write */
#define CMD24                    24              /* Write single block */
#define CMD25                    25              /* Write multi block */
#define ACMD41                   41             /* should return 0x00 */
#define CMD55                    55               /* should return 0x01 */
#define CMD58                    58              /* Read OCR */
#define CMD59                    59               /* CRC disable/enbale, should return 0x00 */



#endif